package com.jrauto.CarAppBackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jrauto.CarAppBackend.model.Series;
import com.jrauto.CarAppBackend.service.SeriesService;
import com.jrauto.CarAppBackend.mapper.SeriesMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author huimin
* @description 针对表【series(汽车车系表)】的数据库操作Service实现
* @createDate 2025-06-27 10:44:05
*/
@Service
public class SeriesServiceImpl extends ServiceImpl<SeriesMapper, Series>
    implements SeriesService{

    @Resource
    private SeriesMapper seriesMapper;

    @Override
    public boolean addSeries(Series series) {
        return save(series);
    }

    @Override
    public Series getSeriesById(Long id) {
        return getById(id);
    }

    @Override
    public boolean updateSeries(Series series) {
        if (series.getId() == null) {
            throw new IllegalArgumentException("更新车系时ID不能为空");
        }
        return updateById(series);
    }

    @Override
    public boolean deleteSeries(Long id) {
        return removeById(id);
    }

    @Override
    public List<Series> getAllSeries() {
        return list();
    }

    @Override
    public List<Series> getSeriesByBrandId(Long brandId) {
        LambdaQueryWrapper<Series> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Series::getId, brandId);
        return list(queryWrapper);
    }



    @Override
    public List<Series> getSeriesByBrand(String brand) {
        LambdaQueryWrapper<Series> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Series::getBrand, brand);
        return list(queryWrapper);
    }
}




